package com.example.controller.shopping;

import com.example.common.Result;

import com.example.model.entity.shopping.MedicinesType;
import com.example.service.shopping.MedicinesTypeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 药物分类表前端操作接口
 **/
@RestController
@RequestMapping("/medicinesType")
@Api(tags = "药物分类接口")
public class MedicinesTypeController {

    @Resource
    private MedicinesTypeService medicinesTypeService;

    /**
     * 新增
     */
    @ApiOperation(value = "新增药物分类")
    @PostMapping("/add")
    public Result add(@RequestBody MedicinesType medicinesType) {
        medicinesTypeService.add(medicinesType);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除药物分类")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        medicinesTypeService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除药物分类")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        medicinesTypeService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改药物分类")
    @PutMapping("/update")
    public Result updateById(@RequestBody MedicinesType medicinesType) {
        medicinesTypeService.updateById(medicinesType);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询药物分类")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        MedicinesType medicinesType = medicinesTypeService.selectById(id);
        return Result.success(medicinesType);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有药物分类")
    @GetMapping("/selectAll")
    public Result selectAll(MedicinesType medicinesType) {
        List<MedicinesType> list = medicinesTypeService.selectAll(medicinesType);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询药物分类")
    @GetMapping("/selectPage")
    public Result selectPage(MedicinesType medicinesType,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<MedicinesType> page = medicinesTypeService.selectPage(medicinesType, pageNum, pageSize);
        return Result.success(page);
    }

}
